package main.java.com.wjs.spring.service;

import com.wjs.spring.mapper.AccountMapper;
import com.wjs.spring.pojo.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class AccountService {
    @Autowired
    private AccountMapper accountMapper;

    @Transactional
    public void transfer(String fromActno, String toActno, double money) {
        // 实现转账逻辑
        Account fromAccount = accountMapper.selectByActno(fromActno);
        Account toAccount = accountMapper.selectByActno(toActno);

        fromAccount.setBalance(fromAccount.getBalance() - money);
        toAccount.setBalance(toAccount.getBalance() + money);

        accountMapper.update(fromAccount);
        accountMapper.update(toAccount);
    }
}